
/**
 * 定位开通状态、开通
 */
interface LocationStateListItemResponse extends BaseResponse{
    /**
     * 状态码
     */
    statusCode:string;
    /**
     * 时间
     */
    dateTime:string;
    /**
     * 错误消息
     */
    messageInfo:string;
    /**
     * 手机号码
     */
    phoneNumber:string;
    /**
     * 是否注册
     */
    isRegister:boolean;
}


/**
 * 定位信息、历史定位
 */
interface LocationListItemResponse extends BaseResponse {
    /**序号 */
    index:any;
    /**
     *  车辆ID
     */
    vehicleId:string;
    /**
     * 客服ID
     */
    userId:string;
    /**
     * 定位时间
     */
    creationTime:string;
    /**
     * 区域
     */
    area:string;
    /**
     * 经度
     */
    longitude:string;
    /**
     * 纬度
     */
    latitude:string;
    /**
     * 定位类型
     */
    locationType:string;
    /**
     * 是否注册
     */
    isRegister:boolean;
}


/**
 * 北斗定位获取车辆最近定位
 */
interface BDNPLocationListItemResponse extends BaseResponse{
    /**
     * 车辆地理位置名称
     */
    adr:string;
    /**
     * 车辆定位时间
     */
    utc:string;
    /**
     * 	速度
     */
    spd:string;
    /**
     * 方向
     */
    drc:string;
    /**
     * 车辆定位纬度
     */
    lat:string;
    /**
     * 车辆定位经度
     */
    lon:string;
    /**
     * 位置基本信息状态位
     */
    bst:string;
    /**
     * 报警状态位
     */
    alc:string;
    /**
     * 扩展车辆信号状态位
     */
    est:string;
}

/**
 * 定位器制单接口返回
 */
interface LocToolAddWayBillResponse extends BaseResponse{
    errorMsg:string
}
/**
 * 定位器解绑
 */
interface LocToolRelieveWayBillResponse extends BaseResponse{
    errorMsg:String
}
// 定位器定位 
interface LocToolGetWayBillResponse extends BaseResponse{
    info:locToolLocationInfo[],
    errorMsg:string
}

interface locToolLocationInfo{
    
          // 地址
          gps_info:string,
          // 纬度
          gps_lat:string,
          // 精度
          gps_lng:string,
          // 定位时间
          gps_time:string
    
}
interface locToolLocationListResponse{
    // 定位器编码
    gpsDeviceID:string
    // 位置信息
    info:locToolLocationInfo[]
}







// interface 
/**
 *  定位服务 
 */
interface ILocationService {
    /**
     * 获取定位开通状态
     * @param vehicleId 车辆ID
     * @param isVehicleLocation 是否为车辆定位
     */
    getLocationState(vehicleId:string, isVehicleLocation:boolean):ng.IHttpPromise<LocationStateListItemResponse>;
    /**
     * 开通
     * @param vehicleId 车辆ID
     * @param isVehicleLocation 是否为车辆定位
     */
    getDredge(vehicleId:string, isVehicleLocation:boolean):ng.IHttpPromise<LocationStateListItemResponse>;
    /**
     * 获取定位信息
     * @param vehicleId 车辆ID
     * @param isVehicleLocation 是否为车辆定位
     */
   getLocation(vehicleId:string, isVehicleLocation:boolean):ng.IHttpPromise<LocationListItemResponse>;
    /**
     * 获取历史定位信息
     * @param vehicleId 车辆ID
     * @param isVehicleLocation 是否为车辆定位
     */
   getHistoryLocation(vehicleId:string, isVehicleLocation:boolean):ng.IHttpPromise<LocationListItemResponse>;
   /**
    * 获取北斗数据
    */
    getList(startTime:string, endTime:string, carCode:string, skip:number, count:number):ng.IHttpPromise<ListResponse<LocationListItemResponse>>;

    /** 北斗定位获取车辆最近定位
     * @param CarNo 车辆号
    */
    getBDNPLocation(CarNo:string):ng.IHttpPromise<BDNPLocationListItemResponse>;
    /**
     * 定位器制单（绑定定位器）
     */
    bindToLocTool(orderId:string,gpsDeviceId:String):ng.IHttpPromise<LocToolAddWayBillResponse>;
    /**
     * 定位器解绑
     */
    relieveLocTool(orderId:String):ng.IHttpPromise<LocToolRelieveWayBillResponse>;
    /**
     * 通过定位器获取定位信息
     */
    getLocInfoByLocTool(orderId:string):ng.IHttpPromise<LocToolGetWayBillResponse>;
    /**
     * 查看订单是否已经绑定定位器
     */
    checkOrderBinded(orderId:String,islocating:boolean):ng.IHttpPromise<BaseResponse>;
    /**
     * 通过定位器获取位置信息
     */
    getLocationListByLocTool(orderId:string):ng.IHttpPromise<locToolLocationListResponse>;
}

class locationService implements ILocationService{
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    getLocationState(vehicleId:string, isVehicleLocation:boolean): ng.IHttpPromise<LocationStateListItemResponse>{
        return this.http<LocationStateListItemResponse>({
            method: "GET",
            url: this.route.getUrl("location/GetLocationState?VehicleID={{vehicleId}}&IsVehicleLocation={{isVehicleLocation}}", {
                vehicleId: vehicleId,
                isVehicleLocation: isVehicleLocation
            })
        });
    }

     getDredge(vehicleId:string, isVehicleLocation:boolean):ng.IHttpPromise<LocationStateListItemResponse>{
        return this.http<LocationStateListItemResponse>({
            method: "GET",
            url: this.route.getUrl("location/Dredge?VehicleID={{vehicleId}}&IsVehicleLocation={{isVehicleLocation}}", {
                 vehicleId: vehicleId,
                 isVehicleLocation: isVehicleLocation
            })
        });
    }

     getLocation(vehicleId:string, isVehicleLocation:boolean): ng.IHttpPromise<LocationListItemResponse> {
        return this.http<LocationListItemResponse>({
            method: "GET",
            url: this.route.getUrl("location/GetLocation?VehicleID={{vehicleId}}&IsVehicleLocation={{isVehicleLocation}}", {
                 vehicleId: vehicleId,
                 isVehicleLocation: isVehicleLocation
            })
        });
    }

    getHistoryLocation(vehicleId:string, isVehicleLocation:boolean): ng.IHttpPromise<LocationListItemResponse> {
        return this.http<LocationListItemResponse>({
            method: "GET",
            url: this.route.getUrl("location/GetHistoryLocation?VehicleID={{vehicleId}}&IsVehicleLocation={{isVehicleLocation}}", {
                 vehicleId: vehicleId,
                 isVehicleLocation: isVehicleLocation
            })
        });
    }

    getList(startTime:string, endTime:string, carCode:string, skip:number, count:number): ng.IHttpPromise<ListResponse<LocationListItemResponse>> {
        return this.http<ListResponse<LocationListItemResponse>>({
            method:"GET",
            url:this.route.getUrl("location?StartTime={{startTime}}&EndTime={{endTime}}&CarCode={{carCode}}&skip={{skip}}&count={{count}}",{
                startTime:startTime,
                endTime:endTime,
                carCode:carCode,
                skip:skip,
                count:count
            })

        });
    }
    getBDNPLocation(CarNo:string): ng.IHttpPromise<BDNPLocationListItemResponse>{
        return this.http<BDNPLocationListItemResponse>({
            method:"GET",
            url:this.route.getUrl("location/GetBDNPLocation?CarNo={{CarNo}}",{
                CarNo:CarNo
            })
        })
    }

    bindToLocTool(orderId:string,gpsDeviceId:string):ng.IHttpPromise<LocToolAddWayBillResponse>{
        return this.http<LocToolAddWayBillResponse>({
            method:"POST",
            url:this.route.getUrl("order/AddWayBill"),
            data:{
                OrderId:orderId,
                GpsDeviceID:gpsDeviceId
            }
        })
    }
    relieveLocTool(orderId:String):ng.IHttpPromise<LocToolRelieveWayBillResponse>{
        return this.http<LocToolAddWayBillResponse>({
            method:"GET",
            url:this.route.getUrl("order/RelieveWayBill/{{id}}",{
                id:orderId
            })
        })
    }
    getLocInfoByLocTool(orderId:string):ng.IHttpPromise<LocToolGetWayBillResponse>{
        return this.http<LocToolGetWayBillResponse>({
            method:"GET",
            url:this.route.getUrl("order/GetWayBill?id={{id}}",{
                id:orderId
            })
        })
    }
    checkOrderBinded(orderId:string,islocating:boolean):ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({
            method:"GET",
            url:this.route.getUrl("app/order/CheckOrderIsLocating?id={{id}}&islocating={{islocating}}",{
                id:orderId,
                islocating:islocating
            })
        })
    }
    getLocationListByLocTool(orderId:string):ng.IHttpPromise<locToolLocationListResponse>{
        return this.http<locToolLocationListResponse>({
            method:"GET",
            url:this.route.getUrl("order/GetLocationList?id={{id}}",{
                id:orderId
            })
        })
    }
    


}


angular.module("locationService",[]).service("locationService",['$http','routeService',locationService]);